package com.hyb.controller;


import com.alibaba.fastjson.JSON;
import com.hyb.entity.Dictionary;
import com.hyb.entity.Product;
import com.hyb.page.PageReq;
import com.hyb.page.VoQuery;
import com.hyb.response.Result;
import com.hyb.service.DictionaryService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  数据字典Controller
 * </p>
 *
 * @author hyb
 * @since 2021-12-29
 */
@RestController
@RequestMapping("/dictionary")
public class DictionaryController {

    @Autowired
    private DictionaryService dictionaryService;

    @RequestMapping(value = "/getStaffState" , method = RequestMethod.GET)
    @ApiOperation("获取员工状态")
    public String getStaffState(){
        List<Dictionary> staffStates = dictionaryService.getStaffStates();

        Map<String,Object> map = new HashMap<>();
        map.put("staffStates",staffStates);
        return JSON.toJSONString(new Result().setCode(200).setMessage("加载成功").setData(map));
    }

    @RequestMapping(value = "/loadDictionaryTypes",method = RequestMethod.GET)
    @ApiOperation("获取数据字典的类型")
    public String loadDictionaryTypes(){
        List<Dictionary> dictionaryTypes = dictionaryService.loadDictionaryType();
        Map<String,Object> map = new HashMap<>();
        map.put("dictionaryTypes",dictionaryTypes);
        return JSON.toJSONString(new Result().setCode(200).setMessage("加载成功").setData(map));
    }

    @RequestMapping(value = "/LoadDictionaries",method = RequestMethod.GET)
    @ApiOperation("获取所有的数据字典")
    public String LoadDictionaries(Integer limit, Integer current,Integer parentId,String dictionaryValue,String dictionaryEntry){
        PageReq pageReq = dictionaryService.loadAllDictionary(limit, current, parentId,dictionaryEntry,dictionaryValue);
        return JSON.toJSONString(new Result().setCode(200).setMessage("加载成功").setData(pageReq));
    }

    @RequestMapping(value = "/saveDictionary",method = RequestMethod.POST)
    @ApiOperation("保存数据字典")
    public String saveDictionary(@RequestBody Dictionary dictionary){
        dictionaryService.saveDictionary(dictionary);
        return JSON.toJSONString(new Result().setCode(200).setMessage("保存成功"));
    }

    @RequestMapping(value = "/loadDictionary",method = RequestMethod.GET)
    @ApiOperation("加载数据字典")
    public String loadDictionary(Integer dictionaryId){
        Dictionary dictionaryByDictionaryId = dictionaryService.getDictionaryByDictionaryId(dictionaryId);
        return JSON.toJSONString(new Result().setCode(200).setMessage("加载成功").setData(dictionaryByDictionaryId));
    }

    @RequestMapping(value = "/updateDictionary",method = RequestMethod.PUT)
    @ApiOperation("修改数据字典")
    public String updateDictionary(@RequestBody Dictionary dictionary){
        dictionaryService.updateDictionary(dictionary);
        return JSON.toJSONString(new Result().setCode(200).setMessage("修改成功"));
    }

    @RequestMapping(value = "/deleteDictionary",method = RequestMethod.DELETE)
    @ApiOperation("删除数据字典")
    public String deleteDictionary(int dictionaryId){
        dictionaryService.deleteDictionary(dictionaryId);
        return JSON.toJSONString(new Result().setCode(200).setMessage("删除成功"));
    }

    @RequestMapping(value = "/loadProductType",method = RequestMethod.GET)
    @ApiOperation("加载产品类型")
    public String loadProductType(){
        List<Dictionary> productType = dictionaryService.getProductType();
        return JSON.toJSONString(new Result().setCode(200).setMessage("加载成功").setData(productType));
    }

    @RequestMapping(value = "/loadSaleTypes",method = RequestMethod.GET)
    @ApiOperation("加载销售状态")
    public String loadSaleTypes(){
        List<Dictionary> saleType = dictionaryService.getSaleType();
        return JSON.toJSONString(new Result().setCode(200).setMessage("加载成功").setData(saleType));
    }

    @RequestMapping(value = "/loadCustomerGrade",method = RequestMethod.GET)
    @ApiOperation("加载客户等级")
    public String loadCustomerGrade(){
        List<Dictionary> customerGrade = dictionaryService.getCustomerGrade();
        return JSON.toJSONString(new Result().setCode(200).setMessage("加载成功").setData(customerGrade));
    }

    @RequestMapping(value = "/loadCustomerSatisfaction",method = RequestMethod.GET)
    @ApiOperation("加载客户满意度")
    public String loadCustomerSatisfaction(){
        List<Dictionary> customerSatisfaction = dictionaryService.getCustomerSatisfaction();
        return JSON.toJSONString(new Result().setCode(200).setMessage("加载成功").setData(customerSatisfaction));
    }

    @RequestMapping(value = "/loadCustomerCredit",method = RequestMethod.GET)
    @ApiOperation("加载客户满意度")
    public String loadCustomerCredit(){
        List<Dictionary> customerCredit = dictionaryService.getCustomerCredit();
        return JSON.toJSONString(new Result().setCode(200).setMessage("加载成功").setData(customerCredit));
    }

    @RequestMapping(value = "/loadOrderTypes",method = RequestMethod.GET)
    @ApiOperation("加载订单状态")
    public String loadOrderTypes(){
        List<Dictionary> orderTypes = dictionaryService.getOrderTypes();
        return JSON.toJSONString(new Result().setCode(200).setMessage("加载成功").setData(orderTypes));
    }

    @RequestMapping(value = "/loadCustomerStates",method = RequestMethod.GET)
    @ApiOperation("加载客户状态")
    public String loadCustomerStates(){
        List<Dictionary> customerStates = dictionaryService.getCustomerStates();
        return JSON.toJSONString(new Result().setCode(200).setMessage("加载成功").setData(customerStates));
    }
}
